<?php
class Controller_SDK extends Controller_Form
{
    public function __construct ($req, $res)
    {
        $this->_form_type = 'sdk';
        parent::__construct($req, $res);

        $this->_list_where = array();
    }

    public function action_index ()
    {
        $this->action_list();
    }

    public function action_create ()
    {
        $post = $this->request->post();
        if (! empty($post))
        {
            $this->rebuild_post_data($post);
            $this->_form_data = $post;
        }

        parent::action_create();
    }

    public function action_update ($nid)
    {
        $post = $this->request->post();
        if (! empty($post))
        {
            $this->rebuild_post_data($post);
            $this->_form_data = $post;
        }
        else
        {
            $data = SDK_API::detail($nid);
            $this->_form_data = $data;
            $this->_form_data['icon'] = explode('|', $data['icon']);
        }

        parent::action_update($nid);
    }

    public function action_detail ($nid)
    {
        $data = SDK_API::detail($nid); 
        $this->_form_data = $data;
        $this->_form_data['icon'] = explode('|', $data['icon']);

        parent::action_detail($nid);
    }

    private function rebuild_post_data (& $post)
    {
        //
        $post['icon'] = implode('|', $post['icon']);
    }
}
